package com.szxw.controller;

import com.szxw.pojo.Blog;
import com.szxw.service.BlogService;
import com.szxw.service.impl.BlogServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @Author: 苏执小威
 * @Email:1410511702@qq.com
 * @Desc:
 * @Date: 2022/5/17 19:35
 */
@Controller
public class BlogController {
    @Autowired
    @Qualifier("BlogServiceImpl")
    private BlogServiceImpl service;

    @RequestMapping("/selectAllBlogs")
    public String selectAllBlogs(Model model){
        List<Blog> blogs = service.selectAllBlogs();
        int count = service.blogConuts();
        model.addAttribute("blogs" ,blogs);
        model.addAttribute("counts" ,count);
        return "index";

    }

    @RequestMapping("/selectById")
    public String selectById(Model model,int id){
        Blog blog = service.selectBlogById(id);
        model.addAttribute("blog",blog);
        return "detail";
    }


}
